#ifndef ELFPARSER_H
#define ELFPARSER_H

#include <QString>
#include <QByteArray>
#include "elfstructs.h"

class ElfParser {
public:
    explicit ElfParser(const QString& filename);
    ~ElfParser();

    bool parse();
    bool isValid() const;
    QString errorString() const;

    const ElfHeader& header() const;
    const QVector<ProgramHeader>& programHeaders() const;
    const QVector<SectionHeader>& sectionHeaders() const;
    const QVector<SymbolEntry>& symbols() const;
    const QVector<QString>& strings() const;

    QString toJson() const;
    QString toText() const;

private:
    bool parseHeader();
    bool parseProgramHeaders();
    bool parseSectionHeaders();
    bool parseSymbols();
    bool parseStrings();

    QString m_filename;
    QByteArray m_data;
    bool m_valid;
    QString m_error;

    ElfHeader m_header;
    QVector<ProgramHeader> m_programHeaders;
    QVector<SectionHeader> m_sectionHeaders;
    QVector<SymbolEntry> m_symbols;
    QVector<QString> m_strings;
};

#endif // ELFPARSER_H
